import numpy as np
import tensorflow.compat.v2 as tf
tf.enable_v2_behavior()
import pandas as pd
from tensorflow import keras
from sklearn.preprocessing import StandardScaler
from sklearn.preprocessing import RobustScaler
from sklearn.preprocessing import MinMaxScaler
from matplotlib import pyplot
import plotly.graph_objects as go
import math
import seaborn as sns
from sklearn.metrics import mean_squared_error
np.random.seed(1)
tf.random.set_seed(1)
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, LSTM, GRU, Dropout, RepeatVector, TimeDistributed
from keras import backend
MODELFILENAME = 'MODELS/LSTM_1h_TFM_2c'
TIME_STEPS=6 #1h
CMODEL = LSTM
UNITS=45
DROPOUT1=0.118
DROPOUT2=0.243
ACTIVATION='tanh'
OPTIMIZER='adam'
EPOCHS=43
BATCHSIZE=30
VALIDATIONSPLIT=0.2
# Code to read csv file into Colaboratory:
# from google.colab import files
# uploaded = files.upload()
# import io
# df = pd.read_csv(io.BytesIO(uploaded['SentDATA.csv']))
# Dataset is now stored in a Pandas Dataframe
df = pd.read_csv('../../data/dadesTFM.csv')
df.reset_index(inplace=True)
df['Time'] = pd.to_datetime(df['Time'])
df = df.set_index('Time')
columns = ['PM1','PM25','PM10','PM1ATM','PM25ATM','PM10ATM']
df1 = df.copy();
df1 = df1.rename(columns={"PM 1":"PM1","PM 2.5":"PM25","PM 10":"PM10","PM 1 ATM":"PM1ATM","PM 2.5 ATM":"PM25ATM","PM 10 ATM":"PM10ATM"})
df1['PM1'] = df['PM 1'].astype(np.float32)
df1['PM25'] = df['PM 2.5'].astype(np.float32)
df1['PM10'] = df['PM 10'].astype(np.float32)
df1['PM1ATM'] = df['PM 1 ATM'].astype(np.float32)
df1['PM25ATM'] = df['PM 2.5 ATM'].astype(np.float32)
df1['PM10ATM'] = df['PM 10 ATM'].astype(np.float32)
df2 = df1.copy()
train_size = int(len(df2) * 0.8)
test_size = len(df2) - train_size
train, test = df2.iloc[0:train_size], df2.iloc[train_size:len(df2)]
train.shape, test.shape
((3117, 7), (780, 7))
#Standardize the data
for col in columns:
scaler = StandardScaler()
train[col] = scaler.fit_transform(train[[col]])
<ipython-input-6-83cecdbc25f8>:4: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy train[col] = scaler.fit_transform(train[[col]]) <ipython-input-6-83cecdbc25f8>:4: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy train[col] = scaler.fit_transform(train[[col]]) <ipython-input-6-83cecdbc25f8>:4: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy train[col] = scaler.fit_transform(train[[col]]) <ipython-input-6-83cecdbc25f8>:4: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy train[col] = scaler.fit_transform(train[[col]]) <ipython-input-6-83cecdbc25f8>:4: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy train[col] = scaler.fit_transform(train[[col]]) <ipython-input-6-83cecdbc25f8>:4: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy train[col] = scaler.fit_transform(train[[col]])
def create_sequences(X, y, time_steps=TIME_STEPS):
Xs, ys = [], []
for i in range(len(X)-time_steps):
Xs.append(X.iloc[i:(i+time_steps)].values)
ys.append(y.iloc[i+time_steps])
return np.array(Xs), np.array(ys)
X_train, y_train = create_sequences(train[[columns[1]]], train[columns[1]])
#X_test, y_test = create_sequences(test[[columns[1]]], test[columns[1]])
print(f'X_train shape: {X_train.shape}')
print(f'y_train shape: {y_train.shape}')
X_train shape: (3111, 6, 1) y_train shape: (3111,)
#afegir nova mètrica
def rmse(y_true, y_pred):
return backend.sqrt(backend.mean(backend.square(y_pred - y_true), axis=-1))
model = Sequential()
model.add(CMODEL(units = UNITS, return_sequences=True, input_shape=(X_train.shape[1], X_train.shape[2])))
model.add(Dropout(rate=DROPOUT1))
model.add(CMODEL(units = UNITS, return_sequences=True))
model.add(Dropout(rate=DROPOUT2))
model.add(TimeDistributed(Dense(1,kernel_initializer='normal',activation=ACTIVATION)))
model.compile(optimizer=OPTIMIZER, loss='mae',metrics=['mse',rmse])
model.summary()
Model: "sequential" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= lstm (LSTM) (None, 6, 45) 8460 _________________________________________________________________ dropout (Dropout) (None, 6, 45) 0 _________________________________________________________________ lstm_1 (LSTM) (None, 6, 45) 16380 _________________________________________________________________ dropout_1 (Dropout) (None, 6, 45) 0 _________________________________________________________________ time_distributed (TimeDistri (None, 6, 1) 46 ================================================================= Total params: 24,886 Trainable params: 24,886 Non-trainable params: 0 _________________________________________________________________
history = model.fit(X_train, y_train, epochs=EPOCHS, batch_size=BATCHSIZE, validation_split=VALIDATIONSPLIT,
callbacks=[keras.callbacks.EarlyStopping(monitor='val_loss', patience=5, mode='min')], shuffle=False)
Epoch 1/43 83/83 [==============================] - 4s 46ms/step - loss: 0.6220 - mse: 0.7354 - rmse: 0.6500 - val_loss: 0.4273 - val_mse: 0.3883 - val_rmse: 0.5027 Epoch 2/43 83/83 [==============================] - 1s 9ms/step - loss: 0.4733 - mse: 0.4572 - rmse: 0.5254 - val_loss: 0.3761 - val_mse: 0.3328 - val_rmse: 0.4416 Epoch 3/43 83/83 [==============================] - 1s 8ms/step - loss: 0.4178 - mse: 0.3927 - rmse: 0.4565 - val_loss: 0.3053 - val_mse: 0.2769 - val_rmse: 0.3617 Epoch 4/43 83/83 [==============================] - 1s 8ms/step - loss: 0.3818 - mse: 0.3511 - rmse: 0.4152 - val_loss: 0.2696 - val_mse: 0.2529 - val_rmse: 0.3163 Epoch 5/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3650 - mse: 0.3347 - rmse: 0.3940 - val_loss: 0.2498 - val_mse: 0.2398 - val_rmse: 0.2869 Epoch 6/43 83/83 [==============================] - 1s 8ms/step - loss: 0.3544 - mse: 0.3254 - rmse: 0.3807 - val_loss: 0.2375 - val_mse: 0.2320 - val_rmse: 0.2670 Epoch 7/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3485 - mse: 0.3203 - rmse: 0.3735 - val_loss: 0.2293 - val_mse: 0.2277 - val_rmse: 0.2548 Epoch 8/43 83/83 [==============================] - 1s 8ms/step - loss: 0.3453 - mse: 0.3177 - rmse: 0.3702 - val_loss: 0.2245 - val_mse: 0.2258 - val_rmse: 0.2480 Epoch 9/43 83/83 [==============================] - 1s 8ms/step - loss: 0.3440 - mse: 0.3170 - rmse: 0.3693 - val_loss: 0.2229 - val_mse: 0.2251 - val_rmse: 0.2457 Epoch 10/43 83/83 [==============================] - 1s 9ms/step - loss: 0.3435 - mse: 0.3163 - rmse: 0.3690 - val_loss: 0.2222 - val_mse: 0.2249 - val_rmse: 0.2450 Epoch 11/43 83/83 [==============================] - 1s 9ms/step - loss: 0.3421 - mse: 0.3155 - rmse: 0.3675 - val_loss: 0.2210 - val_mse: 0.2246 - val_rmse: 0.2439 Epoch 12/43 83/83 [==============================] - 1s 12ms/step - loss: 0.3415 - mse: 0.3153 - rmse: 0.3669 - val_loss: 0.2195 - val_mse: 0.2242 - val_rmse: 0.2425 Epoch 13/43 83/83 [==============================] - 1s 10ms/step - loss: 0.3414 - mse: 0.3148 - rmse: 0.3668 - val_loss: 0.2189 - val_mse: 0.2238 - val_rmse: 0.2419 Epoch 14/43 83/83 [==============================] - 1s 9ms/step - loss: 0.3406 - mse: 0.3149 - rmse: 0.3662 - val_loss: 0.2176 - val_mse: 0.2236 - val_rmse: 0.2410 Epoch 15/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3392 - mse: 0.3138 - rmse: 0.3648 - val_loss: 0.2168 - val_mse: 0.2232 - val_rmse: 0.2402 Epoch 16/43 83/83 [==============================] - 1s 8ms/step - loss: 0.3389 - mse: 0.3139 - rmse: 0.3643 - val_loss: 0.2160 - val_mse: 0.2229 - val_rmse: 0.2395 Epoch 17/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3381 - mse: 0.3135 - rmse: 0.3637 - val_loss: 0.2145 - val_mse: 0.2220 - val_rmse: 0.2378 Epoch 18/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3378 - mse: 0.3132 - rmse: 0.3631 - val_loss: 0.2136 - val_mse: 0.2213 - val_rmse: 0.2367 Epoch 19/43 83/83 [==============================] - 1s 8ms/step - loss: 0.3370 - mse: 0.3130 - rmse: 0.3624 - val_loss: 0.2132 - val_mse: 0.2213 - val_rmse: 0.2365 Epoch 20/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3363 - mse: 0.3126 - rmse: 0.3617 - val_loss: 0.2126 - val_mse: 0.2207 - val_rmse: 0.2356 Epoch 21/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3361 - mse: 0.3130 - rmse: 0.3613 - val_loss: 0.2115 - val_mse: 0.2203 - val_rmse: 0.2344 Epoch 22/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3356 - mse: 0.3120 - rmse: 0.3608 - val_loss: 0.2109 - val_mse: 0.2199 - val_rmse: 0.2336 Epoch 23/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3355 - mse: 0.3120 - rmse: 0.3603 - val_loss: 0.2108 - val_mse: 0.2198 - val_rmse: 0.2336 Epoch 24/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3353 - mse: 0.3118 - rmse: 0.3602 - val_loss: 0.2098 - val_mse: 0.2194 - val_rmse: 0.2322 Epoch 25/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3343 - mse: 0.3114 - rmse: 0.3590 - val_loss: 0.2089 - val_mse: 0.2191 - val_rmse: 0.2310 Epoch 26/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3345 - mse: 0.3114 - rmse: 0.3594 - val_loss: 0.2092 - val_mse: 0.2192 - val_rmse: 0.2314 Epoch 27/43 83/83 [==============================] - 1s 8ms/step - loss: 0.3340 - mse: 0.3108 - rmse: 0.3587 - val_loss: 0.2092 - val_mse: 0.2193 - val_rmse: 0.2315 Epoch 28/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3334 - mse: 0.3110 - rmse: 0.3579 - val_loss: 0.2083 - val_mse: 0.2185 - val_rmse: 0.2300 Epoch 29/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3339 - mse: 0.3108 - rmse: 0.3580 - val_loss: 0.2080 - val_mse: 0.2186 - val_rmse: 0.2296 Epoch 30/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3331 - mse: 0.3108 - rmse: 0.3572 - val_loss: 0.2075 - val_mse: 0.2183 - val_rmse: 0.2287 Epoch 31/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3330 - mse: 0.3107 - rmse: 0.3575 - val_loss: 0.2077 - val_mse: 0.2183 - val_rmse: 0.2290 Epoch 32/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3333 - mse: 0.3105 - rmse: 0.3572 - val_loss: 0.2064 - val_mse: 0.2177 - val_rmse: 0.2272 Epoch 33/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3331 - mse: 0.3102 - rmse: 0.3572 - val_loss: 0.2067 - val_mse: 0.2180 - val_rmse: 0.2276 Epoch 34/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3331 - mse: 0.3104 - rmse: 0.3570 - val_loss: 0.2061 - val_mse: 0.2178 - val_rmse: 0.2269 Epoch 35/43 83/83 [==============================] - 1s 8ms/step - loss: 0.3327 - mse: 0.3101 - rmse: 0.3567 - val_loss: 0.2058 - val_mse: 0.2174 - val_rmse: 0.2266 Epoch 36/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3321 - mse: 0.3092 - rmse: 0.3559 - val_loss: 0.2057 - val_mse: 0.2176 - val_rmse: 0.2264 Epoch 37/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3321 - mse: 0.3096 - rmse: 0.3556 - val_loss: 0.2061 - val_mse: 0.2182 - val_rmse: 0.2271 Epoch 38/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3324 - mse: 0.3092 - rmse: 0.3559 - val_loss: 0.2048 - val_mse: 0.2174 - val_rmse: 0.2254 Epoch 39/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3320 - mse: 0.3096 - rmse: 0.3558 - val_loss: 0.2050 - val_mse: 0.2179 - val_rmse: 0.2259 Epoch 40/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3315 - mse: 0.3095 - rmse: 0.3556 - val_loss: 0.2044 - val_mse: 0.2173 - val_rmse: 0.2248 Epoch 41/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3315 - mse: 0.3091 - rmse: 0.3551 - val_loss: 0.2041 - val_mse: 0.2172 - val_rmse: 0.2243 Epoch 42/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3315 - mse: 0.3093 - rmse: 0.3549 - val_loss: 0.2041 - val_mse: 0.2170 - val_rmse: 0.2246 Epoch 43/43 83/83 [==============================] - 1s 7ms/step - loss: 0.3308 - mse: 0.3089 - rmse: 0.3544 - val_loss: 0.2047 - val_mse: 0.2175 - val_rmse: 0.2254
import matplotlib.pyplot as plt
plt.plot(history.history['loss'], label='MAE Training loss')
plt.plot(history.history['val_loss'], label='MAE Validation loss')
plt.plot(history.history['mse'], label='MSE Training loss')
plt.plot(history.history['val_mse'], label='MSE Validation loss')
plt.plot(history.history['rmse'], label='RMSE Training loss')
plt.plot(history.history['val_rmse'], label='RMSE Validation loss')
plt.legend();
X_train_pred = model.predict(X_train, verbose=0)
train_mae_loss = np.mean(np.abs(X_train_pred - X_train), axis=1)
plt.hist(train_mae_loss, bins=50)
plt.xlabel('Train MAE loss')
plt.ylabel('Number of Samples');
def evaluate_prediction(predictions, actual, model_name):
errors = predictions - actual
mse = np.square(errors).mean()
rmse = np.sqrt(mse)
mae = np.abs(errors).mean()
print(model_name + ':')
print('Mean Absolute Error: {:.4f}'.format(mae))
print('Root Mean Square Error: {:.4f}'.format(rmse))
print('Mean Square Error: {:.4f}'.format(mse))
print('')
return mae,rmse,mse
mae,rmse,mse = evaluate_prediction(X_train_pred, X_train,"LSTM")
LSTM: Mean Absolute Error: 0.1825 Root Mean Square Error: 0.4322 Mean Square Error: 0.1868
model.save(MODELFILENAME+'.h5')
#càlcul del threshold de test
def calculate_threshold(X_test, X_test_pred):
distance = np.sqrt(np.mean(np.square(X_test_pred - X_test),axis=1))
"""Sorting the scores/diffs and using a 0.80 as cutoff value to pick the threshold"""
distance.sort();
cut_off = int(0.9 * len(distance));
threshold = distance[cut_off];
return threshold
for col in columns:
print ("####################### "+col +" ###########################")
#Standardize the test data
scaler = StandardScaler()
test_cpy = test.copy()
test[col] = scaler.fit_transform(test[[col]])
#creem seqüencia amb finestra temporal per les dades de test
X_test1, y_test1 = create_sequences(test[[col]], test[col])
print(f'Testing shape: {X_test1.shape}')
#evaluem el model
eval = model.evaluate(X_test1, y_test1)
print("evaluate: ",eval)
#predim el model
X_test1_pred = model.predict(X_test1, verbose=0)
evaluate_prediction(X_test1_pred, X_test1,"LSTM")
#càlcul del mae_loss
test1_mae_loss = np.mean(np.abs(X_test1_pred - X_test1), axis=1)
test1_rmse_loss = np.sqrt(np.mean(np.square(X_test1_pred - X_test1),axis=1))
# reshaping test prediction
X_test1_predReshape = X_test1_pred.reshape((X_test1_pred.shape[0] * X_test1_pred.shape[1]), X_test1_pred.shape[2])
# reshaping test data
X_test1Reshape = X_test1.reshape((X_test1.shape[0] * X_test1.shape[1]), X_test1.shape[2])
threshold_test = calculate_threshold(X_test1Reshape,X_test1_predReshape)
test1_score_df = pd.DataFrame(test[TIME_STEPS:])
test1_score_df['loss'] = test1_rmse_loss.reshape((-1))
test1_score_df['threshold'] = threshold_test
test1_score_df['anomaly'] = test1_score_df['loss'] > test1_score_df['threshold']
test1_score_df[col] = test[TIME_STEPS:][col]
#gràfic test lost i threshold
fig = go.Figure()
fig.add_trace(go.Scatter(x=test1_score_df.index, y=test1_score_df['loss'], name='Test loss'))
fig.add_trace(go.Scatter(x=test1_score_df.index, y=test1_score_df['threshold'], name='Threshold'))
fig.update_layout(showlegend=True, title='Test loss vs. Threshold')
fig.show()
#Posem les anomalies en un array
anomalies1 = test1_score_df.loc[test1_score_df['anomaly'] == True]
anomalies1.shape
print('anomalies: ',anomalies1.shape); print();
#Gràfic dels punts i de les anomalíes amb els valors de dades transformades per verificar que la normalització que s'ha fet no distorssiona les dades
fig = go.Figure()
fig.add_trace(go.Scatter(x=test1_score_df.index, y=scaler.inverse_transform(test1_score_df[col]), name=col))
fig.add_trace(go.Scatter(x=anomalies1.index, y=scaler.inverse_transform(anomalies1[col]), mode='markers', name='Anomaly'))
fig.update_layout(showlegend=True, title='Detected anomalies')
fig.show()
print ("######################################################")
####################### PM1 ########################### Testing shape: (774, 6, 1)
<ipython-input-17-48420fb1aa44>:8: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy test[col] = scaler.fit_transform(test[[col]])
25/25 [==============================] - 0s 2ms/step - loss: 0.3837 - mse: 0.6042 - rmse: 0.4180 evaluate: [0.383748859167099, 0.6041901707649231, 0.41800791025161743] LSTM: Mean Absolute Error: 0.1836 Root Mean Square Error: 0.5868 Mean Square Error: 0.3444
anomalies: (118, 10)
###################################################### ####################### PM25 ###########################
<ipython-input-17-48420fb1aa44>:8: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
Testing shape: (774, 6, 1) 25/25 [==============================] - 0s 2ms/step - loss: 0.3964 - mse: 0.5425 - rmse: 0.4309 evaluate: [0.3963891267776489, 0.5425150990486145, 0.4308834671974182] LSTM: Mean Absolute Error: 0.1915 Root Mean Square Error: 0.5426 Mean Square Error: 0.2945
anomalies: (95, 10)
###################################################### ####################### PM10 ########################### Testing shape: (774, 6, 1)
<ipython-input-17-48420fb1aa44>:8: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
25/25 [==============================] - 0s 2ms/step - loss: 0.4057 - mse: 0.5119 - rmse: 0.4414 evaluate: [0.405744343996048, 0.5119484663009644, 0.4413897395133972] LSTM: Mean Absolute Error: 0.1959 Root Mean Square Error: 0.5049 Mean Square Error: 0.2549
anomalies: (91, 10)
###################################################### ####################### PM1ATM ########################### Testing shape: (774, 6, 1)
<ipython-input-17-48420fb1aa44>:8: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
25/25 [==============================] - 0s 2ms/step - loss: 0.4085 - mse: 0.5437 - rmse: 0.4450 evaluate: [0.4084767997264862, 0.543734073638916, 0.44501498341560364] LSTM: Mean Absolute Error: 0.1927 Root Mean Square Error: 0.5015 Mean Square Error: 0.2515
anomalies: (91, 10)
###################################################### ####################### PM25ATM ########################### Testing shape: (774, 6, 1)
<ipython-input-17-48420fb1aa44>:8: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
25/25 [==============================] - 0s 2ms/step - loss: 0.4049 - mse: 0.5516 - rmse: 0.4408 evaluate: [0.40490755438804626, 0.5515972971916199, 0.44079139828681946] LSTM: Mean Absolute Error: 0.1911 Root Mean Square Error: 0.5130 Mean Square Error: 0.2632
anomalies: (91, 10)
###################################################### ####################### PM10ATM ########################### Testing shape: (774, 6, 1)
<ipython-input-17-48420fb1aa44>:8: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
25/25 [==============================] - 0s 3ms/step - loss: 0.4042 - mse: 0.5294 - rmse: 0.4397 evaluate: [0.4042035937309265, 0.5293779969215393, 0.43971413373947144] LSTM: Mean Absolute Error: 0.1949 Root Mean Square Error: 0.5166 Mean Square Error: 0.2669
anomalies: (90, 10)
######################################################